Subject: Re: Removing Task started with CreateNewProc
From: [email-masked] (Holger Kruse)
Date: 11 Apr 1994 17:45:44 -0400
Newsgroups: comp.sys.amiga.programmer

[email-masked] (Robert Knop) writes:

>I have a parent process that creates a child process with the dos.library
>CreateNewProc, using the NP_Entry tag (as opposed to the NP_SegList tag).
>When I want to finish the task, the parent process sends a message to the
>child process, telling it to clean up.  The child process cleans up
>_everything_ it has allocated, and then does:

>ReplyMsg(msg);
>Wait(0L);

>When the parent process gets the reply to the "clean up" message, it takes
>that to mean that the child process is cleaned up and ready to be killed, so
>it calls RemTask(childprocess).

I see two problems with your method:
 - Exec might preempt your child task during ReplyMsg(msg), so when
   you RemTask() it, it is still within the ReplyMsg(), and has not
   yet reached the Wait(). This might not be fatal though.
 - Here is the real problem: RemTask() should not be used for DOS
   processes, because DOS processes have a DOS environment, that
   needs cleanup, too. This is done automatically for you if you
   just "fall through", i.e. execute a RTS at the end of your
   subroutine. Then the program executes the necessary DOS-related
   cleanup and removes the task from exec's list.

The code I use in one of my programs looks like this:

main process:

  CreateNewProc(....)
  -- some synchronization for startup --
  [...task is running...]
  Wait(SIGBREAKF_CTRL_F); /* I guess you could use messages instead of
						  signals here, too) */
  /* nothing else to do here. Child task has finished */

child process:

  -- some synchronization for startup --
  [... task is running ...]
  Forbid(); /* necessary to make sure that the task is really removed
			   before the main program _assumes_ that it is gone. */
  Signal(parent,SIGBREAKF_CTRL_F);
  /* fall through to the end of the C function */

If you use messages instead of signals the synchronization gets quite
similar to the one used by Workbench.

Holger Kruse
[email-masked]